
// import * as md5 from '../lib/md5.min';
import * as encoding from '../lib/encoding.min.js';
import { ByteStream } from './ByteStream';
import CommConst from '../const/CommConst';
import UtilTool from './UtilTool';
// export class MD5 {
//     static encode(v): string {
//         return md5(v);
//     }
// }

export class TextCoder{

    static encode(ma:string,str:string){
        UtilTool.printLog(encoding,'encoding');
        
       return  ( new encoding.default.TextEncoder(ma,{ NONSTANDARD_allowLegacyEncoding: true })).encode(str);
    }
    static decode(ma:string,buff:Uint8Array){
        return  (new encoding.default.TextDecoder(ma)).decode(buff);//'gb18030'
    }

}

export class GetByteStream{
    /**前4字节存mid len*/
    public static getStream(mid:number,sid:number,len:number):ByteStream
    {
        var buf:ArrayBuffer = new ArrayBuffer(len + CommConst.HEAD_LEN);
        var bStream:ByteStream = new ByteStream(buf);        

        // bStream.Offset = 2;
        bStream.writeSort(len);//len
        bStream.writeSort(mid);//mid 
        // bStream.writeSort(sid);//sid 
        bStream.Offset = CommConst.HEAD_LEN;

        return bStream
    }
}